{% extends "admin_base.html" %}

{% block title %}Email Settings{% endblock %}

{% block content %}
<div class="col-9">
	<h3>Email Settings</h3><hr />
	<form action="actions/email.php" method="POST">
		<fieldset>
			<div class="form-group col-6 nopad">
				<label for="smail_method" class="control-label">Sendmail Method</label>
				<div>
					<select name="smail_method" class="form-control" id="smail_method">
						<option value="php" {% if settings.sendmail_method == 'php' %}selected="selected"{% endif %}>PHP mail()</option>
						<option value="postmark" {% if settings.sendmail_method == 'postmark' %}selected="selected"{% endif %}>Postmark</option>
						<option value="mandrill" {% if settings.sendmail_method == 'mandrill' %}selected="selected"{% endif %}>Mandrill</option>
						<option value="mailgun" {% if settings.sendmail_method == 'mailgun' %}selected="selected"{% endif %}>Mailgun</option>
						<option value="sendgrid" {% if settings.sendmail_method == 'sendgrid' %}selected="selected"{% endif %}>Sendgrid</option>
					</select>
				</div>
			</div>
			<div class="form-group col-6 nopad-right">
				<label for="sendmail_email" class="control-label">Sendmail Address</label>
				<div>
					<input type="text" name="sendmail_email" class="form-control" value="{{ settings.sendmail_email }}"/>
					<p><small class="text-muted"><em>The email address all outgoing emails should use. If using Postmark, Mandrill, or Mailgun this must match the email used in their settings.</em></small></p>
				</div>
			</div>
			<div class="form-group" id="postmark">
				<label for="postmark_api_key" class="control-label">PostmarkApp API Key</label>
				<div>
					<input type="text" name="postmark_api_key" class="form-control" value="{{ settings.postmark_api_key }}"/>
					<p><small class="text-muted"><em>The API key generated on <a href="https://postmarkapp.com/">Postmark</a>. Leave blank if not using.</em></small></p>
				</div>
			</div>
			<div class="form-group" id="mandrill">
				<label for="mandrill_api_key" class="control-label">Mandrill API Key</label>
				<div>
					<input type="text" name="mandrill_api_key" class="form-control" value="{{ settings.mandrill_api_key }}"/>
					<p><small class="text-muted"><em>The API key generated on <a href="https://mandrill.com/">Mandrill</a>. Leave blank if not using.</em></small></p>
				</div>
			</div>
			<div class="form-group" id="mailgun">
				<label for="mailgun_api_key" class="control-label">Mailgun API Key</label>
				<div>
					<input type="text" name="mailgun_api_key" class="form-control" value="{{ settings.mailgun_api_key }}"/>
					<p><small class="text-muted"><em>The API key generated on <a href="https://mailgun.com/">Mailgun</a>. Leave blank if not using.</em></small></p>
				</div>
			</div>
			<div class="form-group" id="sendgrid">
				<label for="sendgrid_api_key" class="control-label">Sendgrid API Key</label>
				<div>
					<input type="text" name="sendgrid_api_key" class="form-control" value="{{ settings.sendgrid_api_key }}"/>
					<p><small class="text-muted"><em>The API information generated on <a href="https://sendgrid.com/">Sendgrid</a>. Please enter the information as <code>username|password</code>. This field may look different after submitting the information as it is stored in an encrypted manner to protect your password. Leave blank if not using.</em></small></p>
				</div>
			</div>
			<div class="form-group">
				<div>
					<input type="submit" value="Update Email Settings" class="btn btn-primary" />
				</div>
			</div>
		</fieldset>
	</form>
</div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
	function updateActive(){
		var method = "#" + $("#smail_method :selected").val();
		if($(method).not(':visible')){
			$("#postmark,#mailgun,#sendgrid,#mandrill").hide();
			$(method).show();
		}
	}
	$(document).ready(function(){
		updateActive();
		$("#smail_method").change(function(){
			updateActive();
		});
	});
</script>
{% endblock %}